#ifndef MODIFIED_MOORE_3D_1_H
#define MODIFIED_MOORE_3D_1_H
#include "neighbourhoods.h"
#include "ca-pathfinding/grids/grid.h"
#include <vector>

namespace mvnn
{
    //Na pierwszym poziomie zwraca sasiadow wg Moore'a, na drugim komorke powyzej i jej sasiadow wg von Neumana
    // 8+1+4 sasiadow



    Tile* topGrid(Grid* g,int i, int j)
    {

        if(g->start->y/Tile::TILE_SIZE==i && g->start->x/Tile::TILE_SIZE==j)return g->start;
        if(g->stop->y/Tile::TILE_SIZE==i && g->stop->x/Tile::TILE_SIZE==j)return g->stop;
        else return nb::walledTile;
    }


    std::vector<Tile*> neighbours(Grid* g,const int& i,const int& j)
    {
        // N, NE, E, SE, S, SW, W, NW, TOP, N-TOP, E-TOP, S-TOP, W-TOP
        std::vector<Tile*> v(13);
        int width=g->width();
        int height=g->height();
        if(i>0)
        {
            v[0]=g->tiles[i-1][j]; //N
            v[9]=topGrid(g,i-1,j);//N-TOP
        }
        else
        {
            v[0]=nb::notExistingTile; //N
            v[9]=nb::notExistingTile; //N-TOP
        }
        if(j<width-1 && i>0)
        {
            v[1]=g->tiles[i-1][j+1];//NE
        }
        else
        {
            v[1]=nb::notExistingTile;
        }
        if(j<width-1)
        {

            v[2]=g->tiles[i][j+1];//E
            v[10]=topGrid(g,i,j+1);//E-TOP
        }
        else
        {
            v[2]=nb::notExistingTile;//E
            v[10]=nb::notExistingTile;//E-TOP
        }
        if(j<width-1 && i<height-1)
        {
            v[3]=g->tiles[i+1][j+1];//SE
        }
        else
        {
            v[3]=nb::notExistingTile;
        }
        if(i<height-1)
        {
            v[4]=g->tiles[i+1][j];//S
            v[11]=topGrid(g,i+1,j);//S-TOP
        }
        else
        {
            v[4]=nb::notExistingTile;//S
            v[11]=nb::notExistingTile;//S-TOP
        }
        if(j>0 && i<height-1)
        {
            v[5]=g->tiles[i+1][j-1];//SW
        }
        else
        {
            v[5]=nb::notExistingTile;
        }
        if(j>0)
        {
            v[6]=g->tiles[i][j-1];//W
            v[12]=topGrid(g,i,j-1);//W-TOP
        }
        else
        {
            v[6]=nb::notExistingTile;//W
            v[12]=nb::notExistingTile;//W-TOP
        }
        if(i>0 && j>0)
        {
            v[7]=g->tiles[i-1][j-1];//NW
        }
        else
        {
            v[7]=nb::notExistingTile;
        }
        v[8]=topGrid(g,i,j);//top
        return v;
    }
}

#endif // MODIFIED_MOORE_3D_1_H
